import java.util.HashSet;


public class Line {
	private String label;
	private String instruction;
	private String op1 = null;
	private String op2 = null;
	private String op3 = null;
	private String op4 = null;
	private int LC = 0;
	private int statementnumber = 0;
	private String x_binary = null;
	private String s_field_binary = null;
	private int opcount = 0;
	private HashSet<Integer> errors = new HashSet<Integer>();
	
	public Line(int statementnumber, String label, String instruction, int LC, String x, String s_field){
		this.statementnumber = statementnumber;
		this.label = label;
		this.instruction = instruction.toUpperCase();
		this.LC = LC;
		this.x_binary = x;
		this.s_field_binary = s_field;
		this.opcount = 0;
	}
	
	public Line(int statementnumber, String label, String instruction, String op1, int LC,String x, String s_field){
		this.statementnumber = statementnumber;
		this.label = label;
		this.instruction = instruction.toUpperCase();
		this.op1 = op1;
		this.LC = LC;
		this.x_binary = x;
		this.s_field_binary = s_field;
		this.opcount = 1;
	}
	
	public Line(int statementnumber, String label, String instruction, String op1, String op2, int LC, String x, String s_field){
		this.statementnumber = statementnumber;
		this.label = label;
		this.instruction = instruction.toUpperCase();
		this.op1 = op1;
		this.op2 = op2;
		this.LC = LC;
		this.x_binary = x;
		this.s_field_binary = s_field;
		this.opcount = 2;
	}
	
	public Line(int statementnumber, String label, String instruction, String op1, String op2, String op3, int LC, String x, String s_field){
		this.statementnumber = statementnumber;
		this.label = label;
		this.instruction = instruction.toUpperCase();
		this.op1 = op1;
		this.op2 = op2;
		this.op3 = op3;
		this.LC = LC;
		this.x_binary = x;
		this.s_field_binary = s_field;
		this.opcount = 3;
	}
	
	public Line(int statementnumber, String label, String instruction, String op1, String op2, String op3, String op4, int LC, String x, String s_field){
		this.statementnumber = statementnumber;
		this.label = label;
		this.instruction = instruction.toUpperCase();
		this.op1 = op1;
		this.op2 = op2;
		this.op3 = op3;
		this.op4 = op4;
		this.LC = LC;
		this.x_binary = x;
		this.s_field_binary = s_field;
		this.opcount = 4;
	}
	
	public int getStatementNumber(){
		return this.statementnumber;
	}
	
	public String getLabel(){
		return this.label;
	}
	
	public String getInstruction(){
		return this.instruction;
	}

	public int getOpcount(){
		return this.opcount;
	}
	
	public int getLC(){
		return this.LC;
	}

	public String[] getOperands(){
		switch(this.opcount){
		case 0:
			String[] array0 = {""}; 
			return array0;
		case 1:
			String[] array1 = {op1}; 
			return array1;
		case 2:
			String[] array2 = {op1, op2}; 
			return array2;
		case 3:
			String[] array3 = {op1, op2, op3}; 
			return array3;
		case 4:
			String[] array4 = {op1, op2, op3, op4}; 
			return array4;
		default:
			String[] array = {""}; 
			return array;	
		}
	}
	
	@Override 
	public String toString(){
		switch(this.opcount){
		case 0:
			return "Label: " + this.label + " Instruction: " + this.instruction + " LC: " + Integer.toString(LC) + " Operands: ";
		case 1:
			return "Label: " + this.label + " Instruction: " + this.instruction + " LC: " + Integer.toString(LC) + " Operands: " + op1;
		case 2:
			return "Label: " + this.label + " Instruction: " + this.instruction + " LC: " + Integer.toString(LC) + " Operands: " + op1 + ", " + op2;
		case 3:
			return "Label: " + this.label + " Instruction: " + this.instruction + " LC: " + Integer.toString(LC) + " Operands: " + op1 + ", " + op2 + ", " + op3;
		case 4:
			return "Label: " + this.label + " Instruction: " + this.instruction + " LC: " + Integer.toString(LC) + " Operands: " + op1 + ", " + op2 + ", " + op3 + ", " + op4;
		default: 
			return "";	
		}
	}
	
	public String printOps(){
		switch(this.opcount){
		case 0:
			return "";
		case 1:
			return op1;
		case 2:
			return op1 + ", " + op2;
		case 3:
			return op1 + ", " + op2 + ", " + op3;
		case 4:
			return op1 + ", " + op2 + ", " + op3 + ", " + op4;
		default: 
			return "";	
		}
	}
	
	public void addError(int errorcode){
		this.errors.add(errorcode);
	}
	
	public HashSet<Integer> getErrors(){
		return this.errors;
	}
	
	public String getXBin () {
		return this.x_binary;
	}
	
	public String getSFieldBin() {
		return this.s_field_binary;
	}
	
	public void SetSField(String binary){
		s_field_binary = binary;
	}
	
	public void setLC(int lc){
		LC = lc;
	}
}
